package com.example.demo.controller;


import com.example.demo.Interface.DataRepo;
import com.example.demo.entity.Data;
import com.example.demo.entity.Wendu;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Controller
public class Getwendu {

    @Resource
    DataRepo dataRepo;

    @RequestMapping(value="/getWendu")
    @ResponseBody
    public List<Wendu> getwendu(){
        List<Wendu> list = new ArrayList<Wendu>();//温度对象list
        List<Data> optionalData  = dataRepo.findAll();//查询所有数据
        for(Data data:optionalData){
            //System.out.println(data.wendu);
            String time1 = new String(data.time);
            String wendu1 = new String(data.wendu);
            list.add(new Wendu(time1,wendu1));
        }

        System.err.println(list.toString());
        return list;
    }

    @RequestMapping(value="/wendus")
    public String get(){
        return "wendu";
    }

}
